package com.yj.event_listener.util;

import android.os.Build;
import android.util.Log;

import com.yj.event_listener.constants.Constants;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Utils {

    private static SimpleDateFormat sdf;


    public static boolean isToday(long time){
        if (sdf == null){
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        }
        Date now = new Date(time);
        return sdf.format(now).compareTo(sdf.format(new Date())) == 0;
    }

    /**
     * 是否为鸿蒙系统
     *
     * @return true为鸿蒙系统
     */
    public static boolean isHarmony(){

        try {
            Class<?> buildExClass = Class.forName("com.huawei.system.BuildEx");
            Object osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass);
            if (osBrand == null) {
                return false;
            } else {
                Constants.isHarmony = "Harmony".equalsIgnoreCase(osBrand.toString());
                return Constants.isHarmony;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 判断是否是小米手机
     * @return true 为小米手机
     */
    public static boolean isXiaomi(){

        try {
            String manufacture = Build.MANUFACTURER;
            LogUtil.d(manufacture);
            if(manufacture.equals("Xiaomi")){
                Constants.isXiaomi = true;
            }
            return Constants.isXiaomi;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}
